package com.li.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.li.constant.MessageConstant;
import com.li.entity.PageResult;
import com.li.entity.QueryPageBean;
import com.li.entity.Result;
import com.li.pojo.Role;
import com.li.service.RoleService;
import com.li.utils.ThreadLocalUtil;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/role")
public class RoleController {
    @Reference
    RoleService roleService;
    @RequestMapping("/add")
    public Result add(@RequestBody Role role,String[] ids){

        try {
            roleService.add(role,ids);

        }catch (Exception e){
            e.printStackTrace();
            return new Result(false, "新增角色失败");
        }
        return new Result(true,"新增角色成功");
    }

    @RequestMapping("/findByCondition")
    public PageResult findByCondition(@RequestBody QueryPageBean queryPageBean){

            PageResult list = roleService.findByCondition(queryPageBean);
            return list;
    }

    @RequestMapping("/delete")
    public Result delete(Integer roleId){

            roleService.delete(roleId);

        return new Result(true,"删除角色成功");
    }
    @RequestMapping("/findById")
    public Result findById(Integer roleId){

        Role role = roleService.findById(roleId);
        return new Result(true,"删除角色成功",role);
    }

    @RequestMapping("/update")
    public Result update(Integer[] permissionIds,Integer[] menuId,@RequestBody Role role){

        roleService.update(role,permissionIds,menuId);
        return new Result(true,"更新角色成功");
    }
    @RequestMapping("/findAll")
    public Result findAll(){

        List<Role> list=roleService.findAll();
        return new Result(true,"查询角色成功",list);
    }

}
